#include <iostream>

using namespace std;
void multi_CPU(const int* a,const int* b, int* c, int arraysize);
__global__ void multi_GPU(int* a,int* b,int*
c,int row_num,int col_num);
int main() {
    cout << "GPU版本的乘法" << endl;
    int a[5] = {1,2,3,4,5};
    int b[5] = {1,2,3,4,5};
    int c[5] = {0};
    multi_GPU(a,b,c,5);
    for (int i = 0; i < 5; i++) {
        cout << c[i] << " ";
    }
    cout << endl;
    return 0;
}
/*GPU版本的乘法*/
__global__ void multi_GPU(int* a,int* b,int*
c,int row_num,int col_num){
    int row = blockIdx.y * blockDim.y + threadIdx.y;
    int col = blockIdx.x * blockDim.x + threadIdx.x;
    int col_n = blockDim.x * gridDim.x;
    if (col_n > col_num)
        col_n = col_num;
    int i = col + row * col_n;
    c[i] = a[i]* b[i];
}